package form;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Hashtable;


import javax.servlet.http.HttpServletRequest;

import connexion.Connexion;

import rmi.IServeurRmi;

import beans.Erreur;
import beans.Medecin;

public class ValidationConnexion 
{
	public static boolean form(HttpServletRequest request, Medecin medecin, Erreur erreur)
	{

		IServeurRmi serveur = Connexion.connecterServeur();
		ArrayList<Medecin> medecins;
		Hashtable <String, String> err = new Hashtable<String, String>();
		
		try {
			medecins = serveur.listerMedecin();
			medecin.setLogin(request.getParameter("ident"));
			
			for (Medecin medecin2 : medecins) 
			{
				if (medecin2.getLogin().equals(request.getParameter("ident")))
				{
					if (medecin2.getMotDePasse().equals(request.getParameter("mdp")))
						return true;
					else
					{
						err.put("passwd", "mauvais mot de passe");
						return false;
					}
				}
				else
					err.put("login", "mauvais identifiant");
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		
		return false;
	}
}
